<template>
  <div class="list">
        <hour-array :dataonearray="dataonearray"  :sinfo="sinfo" ></hour-array>
  </div>
</template>
<script>
 
import { mapState, mapGetters, mapMutations } from 'vuex'
import hourArray from './components/hourArray/hourArray'
import {  getBusy, catalog } from '@/service/getData' 

 
export default {
  components: {
    hourArray
  },
  data () {
    return {
       left1: 'active-0',

        dataonearray: '',
        datasupermarket: '',
        datafresh: '',

        sinfo:'',
        marketinfo:'',
        freshinfo:'',

        formatTypes: {oneHourUp: 0,superMarket: 1,freshBook: 2},
    }
  },
  created(){
      function run1(){
        var timer;
        timer = setInterval(() => {
            if(this.position) {
              clearInterval(timer);

              //列表
              catalog({
                 storeCode: this.position.storeLocation,//
                  _: Math.random()+10000000,
                  wap: '3.2.2'
              })
              .then((rep) => {
                      let alldata = rep.resultData;
                      if(!alldata)return;
                      
                      this.$store.dispatch('oneHourUp', alldata.oneHourUp);
                      this.dataonearray = this.run(alldata.oneHourUp);       
              })

              //搜索下面的文字
              getBusy({
                    storeCode:this.position.storeLocation,
                    retailFormatType:this.formatTypes.oneHourUp,
                    _: Math.random()+10000000
              })
              .then((json) => {
                this.sinfo = json.resultData;
              });

          }
        },200)
      }


      run1.call(this);
      
      

      // getBusy({
      //       storeCode:'910A',
      //       retailFormatType:this.formatTypes.superMarket,
      //       _: Math.random()+10000000
      // })
      // .then((json) => {
      //   this.marketinfo = json.resultData;
      // });

      // getBusy({
      //       storeCode:'910A',
      //       retailFormatType:this.formatTypes.freshBook,
      //       _: Math.random()+10000000
      // })
      // .then((json) => {
      //   this.freshinfo = json.resultData;
      // });

  },
  methods: {
    run(data1){
      
      for(let i = 0; i < data1.length; i++) {
                var num = 0;
                let img2 = new Image();
                if(!!data1[i].imgUrl){
                  img2.src = data1[i].imgUrl
                  img2.onerror = function(){
                    data1[i].imgUrl = ''
                  }
                }else {
                  data1[i].imgUrl = ''
                }

                // if(data1[i].childCatalogs[0].childCatalogs){
                       
                    for(let m = 0; m < data1[i].childCatalogs.length; m++) {
                            if(data1[i].childCatalogs[m].childCatalogs) {
                                num = num+ data1[i].childCatalogs[m].childCatalogs.length
                                for(let j = 0; j < data1[i].childCatalogs[m].childCatalogs.length; j++) {
                                    if(!!data1[i].childCatalogs[m].childCatalogs[j].imgUrl){
                                      // let img1 = new Image();
                                      // img1.src = data1[i].childCatalogs[m].childCatalogs[j].imgUrl
                                      // img1.onerror = function(){
                                      //   data1[i].childCatalogs[m].childCatalogs[j].imgUrl = '/static/images/pro-default.png'
                                      // }
                                    }else {
                                       data1[i].childCatalogs[m].childCatalogs[j].imgUrl = '/static/images/pro-default.png'
                                    }
                                }
                            }
                    }
                    if(num <= 9 ) {
                      data1[i].showTitle = false ;
                    }else{
                      data1[i].showTitle = true ;
                    }
                // }
                // else {
                //   data1[i].showTopTitle = true ;
                // }

                  
              }
              return data1;
    }
    ,
    ...mapMutations([
       
    ])
  },
  computed: {
      ...mapGetters({
        position: 'position'
      })
  }
}
</script>

<style lang="less">
.list {
  padding-bottom: 2.05rem !important;
}
.pb-100 {
  padding-bottom: 18rem;
}
</style>
 